<template>
  <a-row :gutter="40" class="panel-group">
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['property:site:list']">
      <div class="card-panel" @click="handleClick('/property/site/site')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="table" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            厂站
          </div>
          <count-to :start-val="0" :end-val="siteSize" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['property:room:list']">
      <div class="card-panel" @click="handleClick('/property/site/room')">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="list" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            分室
          </div>
          <count-to :start-val="0" :end-val="roomSize" :duration="3000" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['property:bay:list']">
      <div class="card-panel" @click="handleClick('/property/site/bay')">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="nested" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            间隔
          </div>
          <count-to :start-val="0" :end-val="baySize" :duration="3200" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['property:line:list']">
      <div class="card-panel" @click="handleClick('/property/site/line')">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="tab" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            线路
          </div>
          <count-to :start-val="0" :end-val="lineSize" :duration="3200" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['property:cabinet:list']">
      <div class="card-panel" @click="handleClick('/property/site/cabinet')">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="list" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            机柜
          </div>
          <count-to :start-val="0" :end-val="cabinetSize" :duration="3200" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['property:device:list']">
      <div class="card-panel" @click="handleClick('/property/site/device')">
        <div class="card-panel-icon-wrapper icon-shopping">
          <svg-icon icon-class="skill" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            设备
          </div>
          <count-to :start-val="0" :end-val="deviceSize" :duration="3600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['order:manage']">
      <div class="card-panel" @click="handleClick('/order/work_order?state=0')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="table" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            待分配工单
          </div>
          <count-to :start-val="0" :end-val="orderSize0" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['order:work_order:list']">
      <div class="card-panel" @click="handleClick('/order/work_order?state=1')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="table" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            待办理工单
          </div>
          <count-to :start-val="0" :end-val="orderSize1" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['order:work_order:list']">
      <div class="card-panel" @click="handleClick('/order/work_order?state=2')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="table" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            进行中工单
          </div>
          <count-to :start-val="0" :end-val="orderSize2" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['order:work_order:list']">
      <div class="card-panel" @click="handleClick('/order/work_order?state=3')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="table" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            待评价工单
          </div>
          <count-to :start-val="0" :end-val="orderSize3" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['order:work_order:list']">
      <div class="card-panel" @click="handleClick('/order/work_order?state=4')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="table" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            已完成工单
          </div>
          <count-to :start-val="0" :end-val="orderSize4" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
    <a-col :xs="8" :sm="6" :lg="4" class="card-panel-col" v-hasPermi="['order:work_order:list']">
      <div class="card-panel" @click="handleClick('/scada/record/event_record')">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="message" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">
            监控告警
          </div>
          <count-to :start-val="0" :end-val="eventSize" :duration="2600" class="card-panel-num" />
        </div>
      </div>
    </a-col>
  </a-row>
</template>

<script>
  import CountTo from 'vue-count-to'

  import {
    listDevice,
    getDevice,
    delDevice,
    addDevice,
    updateDevice
  } from "@/api/property/device";
  import {
    listCabinet,
    getCabinet,
    delCabinet,
    addCabinet,
    updateCabinet
  } from "@/api/property/cabinet";
  import {
    listLine,
    getLine,
    delLine,
    addLine,
    updateLine
  } from "@/api/property/line";
  import {
    listBay,
    getBay,
    delBay,
    addBay,
    updateBay
  } from "@/api/property/bay";
  import {
    listRoom,
    getRoom,
    delRoom,
    addRoom,
    updateRoom
  } from "@/api/property/room";
  import {
    listSite,
    getSite,
    delSite,
    addSite,
    updateSite
  } from "@/api/property/site";
  import {
    listWork_order,
    getWork_order,
    delWork_order,
    addWork_order,
    updateWork_order
  } from "@/api/order/work_order";
  import {
    checkPermi,
    checkRole
  } from "@/utils/permission";
  export default {
    components: {
      CountTo
    },
    data() {
      return {
        siteSize: 0,
        roomSize: 0,
        baySize: 0,
        lineSize: 0,
        cabinetSize: 0,
        deviceSize: 0,
        orderSize0: 0,
        orderSize1: 0,
        orderSize2: 0,
        orderSize3: 0,
        orderSize4: 0,
        eventSize: 0
      }
    },
    methods: {
      handleClick(url) {
        this.$router.push(url);
      }
    },
    mounted() {
      if (checkPermi(['property:site:list'])) {
        listSite({
          pageSize: 1
        }).then(response => {
          this.siteSize = response.total;
        });
      }
      if (checkPermi(['property:room:list'])) {
        listRoom({
          pageSize: 1
        }).then(response => {
          this.roomSize = response.total;
        });
      }
      if (checkPermi(['property:bay:list'])) {
        listBay({
          pageSize: 1
        }).then(response => {
          this.baySize = response.total;
        });
      }
      if (checkPermi(['property:line:list'])) {
        listLine({
          pageSize: 1
        }).then(response => {
          this.lineSize = response.total;
        });
      }
      if (checkPermi(['property:cabinet:list'])) {
        listCabinet({
          pageSize: 1
        }).then(response => {
          this.cabinetSize = response.total;
        });
      }
      if (checkPermi(['property:device:list'])) {
        listDevice({
          pageSize: 1
        }).then(response => {
          this.deviceSize = response.total;
        });
      }
      if (checkPermi(['order:manage'])) {
        listWork_order({
          pageSize: 1,
          state: 0
        }).then(response => {
          this.orderSize0 = response.total;
        });
      }
      if (checkPermi(['order:work_order:list'])) {
        listWork_order({
          pageSize: 1,
          state: 1
        }).then(response => {
          this.orderSize2 = response.total;
        });
        listWork_order({
          pageSize: 1,
          state: 2
        }).then(response => {
          this.orderSize2 = response.total;
        });
        listWork_order({
          pageSize: 1,
          state: 3
        }).then(response => {
          this.orderSize3 = response.total;
        });
        listWork_order({
          pageSize: 1,
          state: 4
        }).then(response => {
          this.orderSize4 = response.total;
        });
      }
    }
  }
</script>

<style lang="less" scoped>
  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
      border-color: rgba(0, 0, 0, .05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-people {
          background: #40c9c6;
        }

        .icon-message {
          background: #36a3f7;
        }

        .icon-money {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3
        }
      }

      .icon-people {
        color: #40c9c6;
      }

      .icon-message {
        color: #36a3f7;
      }

      .icon-money {
        color: #f4516c;
      }

      .icon-shopping {
        color: #34bfa3
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width:550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 100%;
      height: 100%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }
</style>
